package gui;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import domein.DomeinController;
import java.awt.BorderLayout;
import java.sql.SQLException;
import java.util.ResourceBundle;

public class VoetafdrukFrame extends javax.swing.JFrame {
	private DomeinController domeinController;
	private JPanel pnlPanel;
	private JScrollPane jScrollPane;
	private int keuze;
	private ResourceBundle resourceBundle;

	public VoetafdrukFrame(DomeinController domeinController) {
		super();
		this.domeinController = domeinController;
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setBackground(new java.awt.Color(90, 116, 142));
			BorderLayout thisLayout = new BorderLayout();
			getContentPane().setLayout(thisLayout);
			this.setResizable(false);
			this.setLocation(new java.awt.Point(300, 200));
			{
				pnlPanel = new VoetafdrukTaal(this, domeinController);
				getContentPane().add(pnlPanel, BorderLayout.CENTER);
				pnlPanel.setPreferredSize(new java.awt.Dimension(10, 10));
			}
			pack();
			this.setSize(600, 390);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void showVragen(int keuze) throws IllegalStateException, SQLException, ClassNotFoundException {
		String taal = ""; String bundle = "BE_";
		getContentPane().removeAll();
		this.keuze = keuze;
		
		switch(keuze){
			case 1: taal = "NED"; bundle+="nl"; break;
			case 2: taal = "ENG"; bundle+="en"; break;
			case 3: taal = "FRA"; bundle+="fr"; break;
			default: taal = "ERROR"; bundle+="nl";
		}
		
		this.resourceBundle = ResourceBundle.getBundle(bundle);

		if(!taal.equals("ERROR")){
			jScrollPane = new JScrollPane();
			this.add(jScrollPane);
			jScrollPane.setBounds(0, 0, 600, 370);
			jScrollPane.setBorder(null);
			{
				JPanel pnlVragen = new VoetafdrukVragen(domeinController, taal, this, resourceBundle);
				jScrollPane.setViewportView(pnlVragen);
				pnlVragen.setBounds(0, 0, 600, 370);
			}
			getContentPane().add(jScrollPane, BorderLayout.CENTER);
		}
		getContentPane().invalidate();
		getContentPane().repaint();
	}
	
	public void showResult(double gewicht) throws IllegalStateException, SQLException, ClassNotFoundException {
		
		getContentPane().removeAll();
		
		
		if(gewicht > 0 && gewicht < 4)
			this.setBackground(new java.awt.Color(112, 141, 94));
		if(gewicht >= 7)
			this.setBackground(new java.awt.Color(141, 95, 95));	
		
		jScrollPane = new JScrollPane();
		this.add(jScrollPane);
		jScrollPane.setBounds(0, 0, 600, 370);
		jScrollPane.setBorder(null);
		{
			JPanel pnlVragen = new VoetafdrukResultaat(gewicht, resourceBundle);
			jScrollPane.setViewportView(pnlVragen);
			pnlVragen.setBounds(0, 0, 600, 370);
		}
		getContentPane().add(jScrollPane, BorderLayout.CENTER);
		
		getContentPane().invalidate();
		getContentPane().repaint();	
	}
}
